﻿// -----------------------------------------------------------------------
// Copyright (c) David Kean. All rights reserved.
// -----------------------------------------------------------------------
extern alias pcl;
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using pcl::System.Adaptation;
using Moq;

namespace Portable.Adaptation
{
    [TestClass]
    public class PlatformAdapterTests
    {
        [TestMethod]
        public void GetOfT_ReturnsResultOfAdapterResolverResolve()
        {
            var adapter = new object();
            var resolver = IAdapterResolverFactory.OverrideResolve(type => adapter);
            PlatformAdapter.SetResolver(resolver);

            var result = PlatformAdapter.Resolve<object>();

            Assert.AreSame(adapter, result);
        }

        [TestMethod]
        public void GetOfT_WhenAdapterResolverThrows_LetsExceptionPassThrough()
        {
            Exception exception = new Exception();
            var resolver = IAdapterResolverFactory.OverrideResolve(type => { throw exception; });
            PlatformAdapter.SetResolver(resolver);

            ExceptionAssert.Throws(exception, () =>
            {
                PlatformAdapter.Resolve<object>();

            });
        }

        [TestMethod]
        public void GetOfT_WhenAdapterResolverReturnsNull_ThrowsPlatformNotSupported()
        {
            var resolver = IAdapterResolverFactory.OverrideResolve(type => null);
            PlatformAdapter.SetResolver(resolver);

            ExceptionAssert.Throws<PlatformNotSupportedException>(() => {

                PlatformAdapter.Resolve<object>();

            });
        }
    }
}
